    package com.example.springboot.controller;

    import com.example.springboot.dto.PostDTO;
    import com.example.springboot.entity.ForumPost;
    import com.example.springboot.service.ForumPostService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.List;

    @RestController
    @RequestMapping("/api/posts")
    public class ForumPostController {

        @Autowired
        private ForumPostService forumPostService;

        @PostMapping
        public Integer createPost(@RequestBody ForumPost post) {
            return forumPostService.createPost(post);
        }


        @GetMapping("/{postId}")
        public PostDTO getPost(@PathVariable Integer postId) {
            return forumPostService.getPostById(postId);
        }

        @GetMapping("/user/{userId}")
        public List<ForumPost> getPostsByUser(@PathVariable Integer userId) {
            return forumPostService.getPostsByUserId(userId);
        }

        @PutMapping("/{postId}")
        public void updatePost(
                @PathVariable Integer postId,
                @RequestBody ForumPost post
        ) {
            forumPostService.updatePost(postId, post);
        }

        @DeleteMapping("/{postId}")
        public void deletePost(@PathVariable Integer postId) {
            forumPostService.deletePost(postId);
        }

        @GetMapping
        public List<ForumPost> getAllPosts() {
            return forumPostService.getAllPosts();
        }
    }